package org.myorg.v4;

/*
 * Shifted Elliptic function
 */

public class F43 extends Fc4{
	public int high = 100;
	public int low = -100;
	public int dim = 1;
	public double org_value(Gene4 ps) {
		FGene4 gene = (FGene4)ps;
		//double x = (high - low)*gene.geneAt(0) + low;
		//double tmp = (Math.PI + 100)*x/100 - 100;

		int sub_l = gene.length/dim;
		String[] sub_str = new String[dim];
		double[] sub_x = new double[dim];
		
		for (int i = 0; i < dim; i++) {
			sub_str[i] = gene.gene.substring(i*sub_l,(i+1)*sub_l);
			double tem = Long.parseLong(sub_str[i], 2);
			double scope = Math.pow(2, sub_str[i].length()) - 1;
			
			sub_x[i] = tem/scope;

		}

		return fc(sub_x);
	}

	public double fc(double[] scope) {
		
		double y = 0;
		
		double n = scope.length;
		
		double t1 = Math.pow(Math.pow(10, 6), 1);
		
		double tmp = (high - low)*scope[0] + low;
			
		y = tmp*tmp;	
				
		for (int i = 1; i < n; i++ ) {
			tmp = (high - low)*scope[i] + low;
			y = y + Math.pow(Math.pow(10, 6), ((double)i)/(n-1))*tmp*tmp;
		}
		
		return -y;
		
	}
	
}
